#define USE_NEW_SUBST
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Comdiv{
#if MONORAIL
    internal static partial class MainExtensionSet
    {
#else
    public static partial class MainExtensionSet{
#endif
        public static RegexOptions DefaultOptions = RegexOptions.Compiled;
        public static int DefaultRegexTimeout = 2000;
        public static object safeSync = new object();

        public static Regex toRegex(this string pattern){
            return pattern.toRegex(RegexOptions.None);
        }

        public static Regex toRegex(this string pattern, RegexOptions options){
            return new Regex(pattern, options | DefaultOptions);
        }


        public static IDictionary<string, string> toDictionary(this Regex regex, string text){
            Match m = regex.Match(text);
            if (!m.Success){
                return new Dictionary<string, string>();
            }
            string[] ss = regex.GetGroupNames();
            var result = new Dictionary<string, string>();
            foreach (string s in ss){
                result[s] = m.Groups[s].Value;
            }
            return result;
        }
    }
}